package partParsers;

import java.io.IOException;

//this class extracts advertisment data table from real estate html
public class InternTableParser extends InternAdvertParser {
	//Constructor
	public InternTableParser(String buf,String idToken,int indexes[])
	{
		super(buf,idToken,indexes);		
	}
	
	//	Method search for advertisments column names strings
	//initialize 'data' attributes
	//!!!Assumes that 'buffer' and 'indexes' already initialized.
	public boolean parse() throws IOException 
	{
	
		data=new String[indexes.length][1];
		int startPos,pos,midPos;
		
		//pass every idDataToken to read each advertisment
		for(int i=0;i<indexes.length;i++)
		{			
			//look for first table after start of this advertisment data.			
			pos=txtFinder.indexOf(idToken+String.valueOf(indexes[i]));
			if(pos>=0)
			{
				startPos=txtFinder.indexOf("<TABLE",pos);
				pos=txtFinder.indexOf("</TABLE>",startPos);
				midPos=startPos;
				do
				{
					midPos=txtFinder.substring(startPos+6,pos).indexOf("<TABLE",midPos);
					if(midPos<0)
						break;
					startPos+=midPos;				
				}while(midPos>=0);
			
				//insert all html text between tags of table into sat[i]
				data[i][0]= txtFinder.substring(startPos,pos+8);
			}
		}		
		return true;		
	}
}
